let nums = [1,3,-1,-3,5,3,6,7], k = 3
var maxSlidingWindow = function(nums, k) {
    let arr = []
    for(let i=0;i<k;i++){
        while(arr.length&&nums[i]>nums[arr[arr.length-1]]){
            arr.pop()
        }
        arr.push(i)
    }
    const result = [nums[arr[0]]]
    for(let j=k;j<nums.length;j++){
    while(arr.length&&nums[j]>=nums[arr[arr.length-1]]){
            arr.pop()
        }
        arr.push(j)
    while(arr[0]<=j-k){
        arr.shift()
    }
    result.push(nums[arr[0]])
    }
    return result
};
console.log(maxSlidingWindow(nums,k));